package com.sgb.knowledgeshare.view.fragment;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.databinding.FragmentShareMessageBinding;
import com.sgb.knowledgeshare.entity.ShareMagCountEntity;
import com.sgb.knowledgeshare.view.activity.ShareCommentMagessActivity;
import com.sgb.knowledgeshare.view.activity.ShareMagessFansActivity;
import com.sgb.knowledgeshare.view.activity.ShareMagessLandActivity;
import com.sgb.knowledgeshare.view.activity.ShareSystemMagessActivity;
import com.sgb.knowledgeshare.viewmodel.ShareMessageModel;
import com.swgk.core.base.AppFragment;
/**
 * 分享-消息
 */
public class ShareMessageFragment extends AppFragment {
    ShareMessageModel viewmode;
    private FragmentShareMessageBinding binding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_share_message, container, false);
        viewmode = new ViewModelProvider(this).get(ShareMessageModel.class);
        viewmode.setActivity(ShareMessageFragment.this);
        View decor = getActivity().getWindow().getDecorView();
        decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initview();
    }

    private void initview() {
        binding.include.ivBack.setVisibility(View.GONE);
        binding.include.titleView.setText("消息");
        binding.llMagessFans.setOnClickListener(this);//粉丝
        binding.llMagessLaud.setOnClickListener(this);//赞
        binding.llService.setOnClickListener(this);//系统消息
        binding.llMagessComment.setOnClickListener(this);//评论
    }

    @Override
    public void onResume() {
        super.onResume();
        viewmode.getMsgCount();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ll_magess_fans) {//粉丝
            ShareMagessFansActivity.start(getContext());
        } else if (id == R.id.ll_magess_laud) {//赞
            ShareMagessLandActivity.start(getContext());
        } else if (id == R.id.ll_service) {//系统消息
            ShareSystemMagessActivity.start(getContext());
        } else if (id == R.id.ll_magess_comment) {//评论消息
            ShareCommentMagessActivity.start(getContext());
        }
    }

    public void setCount(ShareMagCountEntity data) {
        //系统消息未读数量
        if (data.getCount() > 0) {
            binding.msgServiceCount.setVisibility(View.VISIBLE);
            if (data.getCount() > 99) {
                binding.msgServiceCount.setText(99+"+");
            }else {
                binding.msgServiceCount.setText(data.getCount()+"");
            }
        }else {
            binding.msgServiceCount.setVisibility(View.GONE);
        }
        //最新评论未读数量
        if (data.getCommentCount() > 0) {
            binding.msgCommentCount.setVisibility(View.VISIBLE);
            if (data.getCommentCount()> 99) {
                binding.msgCommentCount.setText(99+"+");
            }else {
                binding.msgCommentCount.setText(data.getCommentCount()+"");
            }
        }else {
            binding.msgCommentCount.setVisibility(View.GONE);
        }
        //最新赞未读数量
        if (data.getLaudCount() > 0) {
            binding.msgLaudCount.setVisibility(View.VISIBLE);
            if (data.getLaudCount()> 99) {
                binding.msgLaudCount.setText(99+"+");
            }else {
                binding.msgLaudCount.setText(data.getLaudCount()+"");
            }
        }else {
            binding.msgLaudCount.setVisibility(View.GONE);
        }
        //最新粉丝未读数量
        if (data.getFansCount() > 0) {
            binding.msgFansCount.setVisibility(View.VISIBLE);
            if (data.getFansCount()> 99) {
                binding.msgFansCount.setText(99+"+");
            }else {
                binding.msgFansCount.setText(data.getFansCount()+"");
            }
        }else {
            binding.msgFansCount.setVisibility(View.GONE);
        }

    }
}
